<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8" />
	<title> 连词成句分词</title>
	
</head>
<script type="text/javascript">
	function toWords(){
		document.getElementById("words").innerHTML="";
		var txt=document.getElementById("sentence").value;
		var txtArr=txt.split("\n");
		var sortFlag=document.getElementById("sort").checked;
		var num=1;
		for(var i=0;i<txtArr.length;i++){
			var sentence=txtArr[i].trim();
			if(sentence){
				var sentenceArr=sentence.split(" ");
				if(!("I"==sentenceArr[0]||sentenceArr[0].indexOf("I'")==0||sentenceArr[0].indexOf("I’")==0)){
					sentenceArr[0]=sentenceArr[0].toLowerCase();
				}
				//标点符号
				var punctuation=sentence[sentence.length-1];
				//最后一个元素去符号
				sentenceArr[sentenceArr.length-1]=sentenceArr[sentenceArr.length-1]	.substring(0, sentenceArr[sentenceArr.length-1].length-1);
				sentenceArr.sort(function(){return Math.random()>0.5?-1:1;});
				var words="<div>";
				if(sortFlag){
					words+=num+". ";
					num++;
				}
				for(var j=0;j<sentenceArr.length-1;j++){
					if(sentenceArr[j]){
						words+=sentenceArr[j]+", ";
					}
				}
				// 1.最后一个不加逗号  2.加上标点符号    
				words+=sentenceArr[sentenceArr.length-1]+" ("+punctuation+")</div>";
				var html=document.getElementById("words").innerHTML+=words;
			}
		}	
	}
	function hide(){
		document.getElementById("tip").style.display = "none";
	}
    function show(){
		document.getElementById("tip").style.display = "";
    }	
/*
I love three things in this world Sun moon and you Sun for morning moon for night and you forever.
Life has taught us that love does not consist in gazing at each other but in looking outward together in the same direction.
*/
</script>
<body>
	<textarea id="sentence" style="width:100%;height:400px;" placeholder='输入整句'></textarea>
	<input type='submit' onclick="toWords()" value="开始分词"/><input type="checkbox" id="sort" style="margin-left:20px"/>序号
	<div id='words'></div>
	<div  style="position:fixed; bottom:5px; right: 5px;font-size:10px;color:grey">
	<span style="margin-right:20px;display:none;" id="tip" >句首为专有名词或人名需手动改为大写</span>
	<span style="margin-right:20px"onmouseover ="show()"onmouseout="hide()">Tips</span>
	Author：Roy</div>
</body>
</html>
